package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.UserCollectionService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.CollectionRequestVo;
import com.rm.zeyou.vo.response.SelectUserCollectionListResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Api(tags = "用户收藏相关")
@RestController
@RequestMapping("/api/userCollection")
public class UserCollectionController {
    @Resource
    private UserCollectionService userCollectionService;
    @Resource
    private LoginUtil loginUtil;

    @ApiOperation(value = "收藏")
    @PostMapping("collection")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> collection(@RequestBody CollectionRequestVo requestVo) {
        User user = loginUtil.getUser();
        return userCollectionService.collection(user.getId(),requestVo);
    }


    @ApiOperation(value = "查询用户收藏列表")
    @PostMapping("selectUserCollectionList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<SelectUserCollectionListResponseVo>> selectUserCollectionList(@RequestBody CollectionRequestVo requestVo) {
        User user = loginUtil.getUser();
        return userCollectionService.selectUserCollectionList(user.getId(),requestVo);
    }
}
